package org.bing.engine.core.domain;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class InstanceConfig extends AbstractEntity {
    private static final long serialVersionUID = 1978L;
    private Map<String, Object> attributes = new HashMap<String, Object>();
    private Domain domain;
    private Application application;
    private Container container;

    @SuppressWarnings({ "unchecked", "rawtypes" })
    public InstanceConfig addAttribute(String name, Object value) {
        if (attributes.containsKey(name) && attributes.get(name) instanceof List) {
            Object old = attributes.get(name);
            ((List) old).add(value);
        } else {
            List list = new ArrayList();
            list.add(value);
            attributes.put(name, list);
        }
        return this;
    }

    public Domain getDomain() {
        return domain;
    }

    public void setDomain(Domain domain) {
        this.domain = domain;
    }

    public Container getContainer() {
        return container;
    }

    public void setContainer(Container container) {
        this.container = container;
    }

    public Application getApplication() {
        return application;
    }

    public void setApplication(Application application) {
        this.application = application;
    }

    public InstanceConfig setAttribute(String name, java.io.Serializable value) {
        attributes.put(name, value);
        return this;
    }

    public Object getAttribute(String name) {
        return attributes.get(name);
    }

    @SuppressWarnings("unchecked")
    public List<Object> getAttributeAsList(String name) {
        return (List<Object>) attributes.get(name);
    }
}
